
class Node {
    constructor(value, next){
        this.value = value
        this.next = next || null
    }
}

class NodeList {
    constructor() {
        this.length = 0
        this.head = null
    }

    addNode() {

    }
}

export default NodeList





/**
 * LRU算法；Map 类型按照 set 顺序来
 * @param {number} capacity
 */
 var LRUCache = function(capacity) {
    this.length = capacity
    this.cache = new Map()
};

/** 
 * @param {number} key
 * @return {number}
 */
LRUCache.prototype.get = function(key) {
    const value = this.cache.get(key)
    this.cache.delete(key)
    this.cache.set(key, value)

    return value?value:-1
};

/** 
 * @param {number} key 
 * @param {number} value
 * @return {void}
 */
LRUCache.prototype.put = function(key, value) {
    if(this.cache.has(key)){
        this.cache.delete(key)
    }
    else if(this.cache.size >= this.length){
        const lastKey = this.cache.keys().next().value
        this.cache.delete(lastKey)
    }
    this.cache.set(key, value)
    // map.keys 是一个 iterator 类型，可以使用 next() 获取 value
    console.log("keys:", this.cache.keys())
};

/**
 * Your LRUCache object will be instantiated and called as such:
 * var obj = new LRUCache(capacity)
 * var param_1 = obj.get(key)
 * obj.put(key,value)
 */

// 测试代码
// var obj = new LRUCache(2)
// obj.put(2,1)
// obj.put(2,2)
// obj.get(2)
// obj.put(1,1)


